package com.ews.onlineexchange.controller.activitii;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.enterprise.inject.Model;
import javax.inject.Inject;

import org.activiti.engine.task.Task;
import org.activiti.engine.task.TaskQuery;

import com.ews.onlineexchange.controller.assess.AssessRecordForSupplierList;

@Model
public class SupplierReviewAssessRecordTaskList extends BpmList {
	
	@Inject
	AssessRecordForSupplierList assessRecordForSupplierList;
	
	private Map<String, Task> dictTaskMap;

	@Override
	TaskQuery createTaskQuery() {
		TaskQuery taskQuery = taskService.createTaskQuery();

		String username = userService.getLoginedUser().getUsername();
		taskQuery.taskAssignee( username );
		taskQuery.processVariableValueEquals( "periodTypeName", assessRecordForSupplierList.getPeriodType().name() );
		
		taskQuery.includeProcessVariables();
		
		taskQuery.orderByTaskCreateTime();
		taskQuery.asc();
		
		return taskQuery;
	}	
	
	public Map<String, Task> getDictTaskMap() {
		if ( dictTaskMap == null ) {
			List<Task> resultList = getResultList();
			Map<String, Task> resultMap = new HashMap<String, Task>();
			for ( Task task : resultList ) {
				resultMap.put( task.getProcessVariables().get( "dictId" ).toString(), task );
			}
			
			dictTaskMap = resultMap;
		}
		
		return dictTaskMap;
	}
	
}
